package me.leiusual.sharing.ui.cart.adapter

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import me.leiusual.sharing.R
import me.leiusual.sharing.api.model.cartdetail.CartX

/**
 * author: leiusual
 * create on: 2019-07-27
 * description:
 */
class CartHomeChildAdapter(
    private val changeListener: () -> Unit,
    private val amountListener: (CartX) -> Unit
) : RecyclerView.Adapter<CartHomeChildViewHolder>() {

  private var dataSet = emptyList<CartX>()

  override fun getItemCount(): Int {
    return dataSet.size
  }

  override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CartHomeChildViewHolder {
    val inflater = LayoutInflater.from(parent.context)
    val itemView = inflater.inflate(R.layout.view_holder_cart_home_child, parent, false)
    return CartHomeChildViewHolder(itemView, changeListener, amountListener)
  }

  override fun onBindViewHolder(holder: CartHomeChildViewHolder, position: Int) {
    holder.bind(dataSet[position])
  }

  fun submitList(list: List<CartX>) {
    this.dataSet = list
    notifyDataSetChanged()
  }
}